#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+3;
int n,m,q,f[N],kx[N],ky[N];
struct Nod{int y,z;};
vector<Nod>ve[N];
ull a[N],b[N],p[73];
bool used[N];
mt19937_64 rd(time(0));
int F(int x){return f[x]==x?x:f[x]=F(f[x]);}
void Dfs(int x,int fa)
{
	for(Nod t:ve[x])if(t.y!=fa)Dfs(t.y,x),b[t.z]=a[t.y],a[x]^=a[t.y];
}
bool Ins(ull x)
{
	for(int i=63;i>=0;i--)if(x>>i&1)
	{
		if(!p[i]){p[i]=x;return 1;}
		x^=p[i];
	}
	return 0;
}
int main()
{
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;iota(f,f+n+1,0);
	for(int i=1,x,y;i<=m;i++)
	{
		cin>>x>>y;ull z=rd();kx[i]=x;ky[i]=y;
		if(F(x)==F(y)){a[x]^=z;a[y]^=z;b[i]=z;continue;}
		f[F(x)]=F(y);ve[x].push_back({y,i});ve[y].push_back({x,i});
	}
	Dfs(1,0);cin>>q;
	for(int i=1;i<=m;i++)if(used[i])b[i]=a[kx[i]]^a[ky[i]];
	while(q--)
	{
		memset(p,0,sizeof(p));int len,fl=0;cin>>len;
		for(int i=1,x;i<=len;i++)
		{
			cin>>x;
			if(!Ins(b[x]))fl=1; 
		}
		puts(fl?"NO":"YES");
	}
}
